home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Deutsche Edition 1
/
Deutsche Edition 1.iso
/
amok
/
031-040
/
amok32
/
ringbuffers
/
syncdemo.mod
< prev
next >
Wrap
Text File
|
1993-11-04
|
3KB
|
105 lines
(**********************************************************************
:Program. SyncDemo.mod
:Contents. Zeigt die Häufigkeit von einzelnen Zeichen einer Datei an
:Remark. Gegenbeispiel zu "MultitaskDemo"
:Author. Nicolas Benezan [bne]
:Address. Postwiesenstr. 2, D7000 Stuttgart 60
:Phone. 711/333679
:Copyright. Public Domain
:Language. Modula-2
:Translator. M2Amiga A+L V3.27d
:Imports. BackDrop [Bernd Preusing], TaskMemory [bne]
:History. V1.0 [bne] 01.Jan.1990
**********************************************************************)
MODULE SyncDemo;
FROM Arguments IMPORT GetArg, NumArgs;
FROM Arts IMPORT Assert, TermProcedure;
FROM BackDrop IMPORT BdRp, OpenBackDrop;
FROM Dos IMPORT Close, Delay, Examine, FileHandlePtr, FileInfoBlock,
FileInfoBlockPtr, FileLockPtr, Lock, oldFile, Open,
Read, sharedLock, UnLock;
FROM Graphics IMPORT SetAPen, WritePixel;
FROM TaskMemory IMPORT Allocate, Deallocate;
FROM SYSTEM IMPORT ADR;
CONST
BufferSize = 256;
Usage = 'Usage = "SyncDemo" FileName.';
VAR
Count: ARRAY CHAR OF LONGINT;
File: FileHandlePtr;
FileName: ARRAY [0..31] OF CHAR;
Buffer: ARRAY [0..BufferSize - 1] OF CHAR;
Size, TotalSize, Position: LONGINT;
Len: INTEGER;
PROCEDURE Cleanup;
BEGIN
IF File # NIL THEN
Close (File);
File:= NIL;
END;
END Cleanup;
PROCEDURE Draw (NumChars: CARDINAL);
VAR
i: INTEGER;
Char: CHAR;
Dummy: LONGINT;
BEGIN
FOR i:= 0 TO NumChars - 1 DO
Char:= Buffer[i];
INC (Position);
SetAPen (BdRp, 3);
Dummy:= WritePixel (BdRp, Position * 640 DIV TotalSize, 0);
INC (Count[Char]);
SetAPen (BdRp, 2);
Dummy:= WritePixel (BdRp, Count[Char], ORD (Char) + 1);
SetAPen (BdRp, 1);
Dummy:= WritePixel (BdRp, Count[Char] * 640 DIV TotalSize,
ORD (Char) + 1);
END;
END Draw;
PROCEDURE FileSize (Name: ARRAY OF CHAR): LONGINT;
VAR
FileLock: FileLockPtr;
Info: FileInfoBlockPtr;
Size: LONGINT;
BEGIN
Allocate (Info, SIZE (FileInfoBlock));
Assert (Info # NIL, ADR ("No free store"));
FileLock:= Lock (ADR (Name), sharedLock);
Assert (FileLock # NIL, ADR ("Lock() failed"));
Assert (Examine (FileLock, Info), ADR ("Examine() failed"));
Size:= Info^.size;
Deallocate (Info);
UnLock (FileLock);
RETURN Size;
END FileSize;
BEGIN
File:= NIL;
TermProcedure (Cleanup);
Assert (NumArgs () = 1, ADR (Usage));
GetArg (1, FileName, Len);
File:= Open (ADR (FileName), oldFile);
Assert (File # NIL, ADR ("File not found"));
TotalSize:= FileSize (FileName);
OpenBackDrop (2, 640, 257, ADR ("SyncDemo"));
Size:= BufferSize;
Position:= 0;
REPEAT
Size:= Read (File, ADR (Buffer), Size);
Assert (Size >= 0, ADR ("Read error"));
Draw (Size);
UNTIL Size < BufferSize;
Delay (250);
END SyncDemo.